package com.example.demo.application.integration;

import org.springframework.stereotype.Service;

import com.example.demo.application.dto.Result;
import com.example.demo.application.dto.UserBodyDto;
import com.example.demo.application.dto.UserReq;
import com.example.demo.domain.user.dto.UserDto;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class UserFeignClientWrapper {

	private final UserFeignClient userFeignClient;

	public UserDto getById(String userId) {
		// 1、根据 userId 构建请求参数
		UserReq userReq = UserReq.from(userId);
		// 2、远程查询用户信息
		Result<UserBodyDto> result = userFeignClient.getById(userReq);
		// 3、判断是否正常返回
		if (result.getRet() == 0 && result.getBody() != null) {
			result.getBody().getUser();
		}
		return null;
	}
}
